<script setup lang="ts">
import {useUserStore} from "../../../stores/userStore.ts";
import {useRouter} from "vue-router";
import {Lock, User} from "@element-plus/icons-vue";

let userStore = useUserStore();

const router = useRouter();

const menuItems = [
  {
    title: '个人资料',
    path: '/profile/edit',
    icon: User
  },
  {
    title: '账号安全',
    path: '/profile/secure',
    icon: Lock
  }
];
</script>

<template>
  <div class="profile-sidebar">
    <div class="sidebar-user">
      <div class="sidebar-avatar">
        <img
            :src="userStore.loginUser.avatar"
            alt="用户头像"
        />
      </div>
      <div class="sidebar-username">
        {{ userStore.loginUser.username }}
      </div>
    </div>
    <el-divider class="divider"/>
    <div class="menu-list">
      <div
          v-for="item in menuItems"
          :key="item.path"
          class="menu-item"
          :class="{ active: $route.path === item.path }"
          @click="router.push(item.path)"
      >
        <el-icon class="menu-icon">
          <component :is="item.icon"/>
        </el-icon>
        {{ item.title }}
      </div>
    </div>
  </div>
</template>

<style scoped>
.profile-sidebar {
  width: 200px;
  flex-shrink: 0;
}

.sidebar-user {
  padding: 24px;
  text-align: center;
  border-radius: 8px;
  margin-bottom: 12px;
}

.sidebar-avatar {
  width: 80px;
  height: 80px;
  margin: 0 auto 12px;
  border-radius: 8px;
  overflow: hidden;
}

.sidebar-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sidebar-username {
  font-size: 16px;
  font-weight: 500;
  color: #262626;
  line-height: 1.5;
  word-break: break-all;
}

.menu-list {
  border-radius: 8px;
  overflow: hidden;
}

.menu-item {
  padding: 16px 20px;
  cursor: pointer;
  transition: all 0.3s;
  color: #262626bf;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.menu-item:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

.menu-item.active {
  background-color: rgba(0, 0, 0, 0.04);
  color: rgb(0 122 255);
  font-weight: 500;
}

.menu-icon {
  font-size: 18px;
}

.divider {
  margin: 10px !important;
}
</style>